//
//  CJShadowTableViewCell.m
//  KaiJing
//
//  Created by lanou on 16/1/15.
//  Copyright © 2016年 HuangZuCui. All rights reserved.
//

#import "CJShadowTableViewCell.h"
#import <UIImageView+WebCache.h>
@implementation CJShadowTableViewCell




- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        
     
        

        _imageV = [[UIImageView alloc] initWithFrame:CGRectMake(0, 10, kScreenWidth, kScreenWidth / 5 * 3)];
        _imageV.backgroundColor = kRandomClolor;
        [self.contentView addSubview:_imageV];
        
        
        
        //标题
        _titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, _imageV.bottom + 10, kScreenWidth - 20, 40)];
        _titleLabel.textAlignment = NSTextAlignmentCenter;
        _titleLabel.numberOfLines = -1;
        _titleLabel.font = [UIFont systemFontOfSize:18];
        [self.contentView addSubview:_titleLabel];
        
        
        //内容
        _contentLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, _titleLabel.bottom + 10, kScreenWidth - 20, 20)];
        _contentLabel.textAlignment = NSTextAlignmentCenter;
        _contentLabel.numberOfLines = -1;
        _contentLabel.font = [UIFont systemFontOfSize:15];
        [self.contentView addSubview:_contentLabel];
              
    }
    return self;
}


- (void)setModel:(CJShadowListModel *)model {
    
    _model = model;
    NSString *urlStr = [NSString stringWithFormat:@"http://morguo.com/%@",_model.image];
    [_imageV sd_setImageWithURL:[NSURL URLWithString:urlStr]];
    
    _titleLabel.text = _model.name;
    
    CGFloat height = [CJShadowTableViewCell cellOfContentLabelHeight:_model];
    _contentLabel.frame = CGRectMake(10, _titleLabel.bottom + 10, kScreenWidth - 20, height);
    _contentLabel.text = _model.desc;

}








+(CGFloat)cellOfContentLabelHeight:(CJShadowListModel *)model
{
    
    NSDictionary *dic = @{NSFontAttributeName:[UIFont systemFontOfSize:15]};
    
    CGRect frame = [model.desc boundingRectWithSize:CGSizeMake(kScreenWidth - 20, CGFLOAT_MAX) options:(NSStringDrawingUsesLineFragmentOrigin) attributes:dic context:nil];
    
    return frame.size.height;
    
}




- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
